package Stream流;

import javax.lang.model.element.NestingKind;
import javax.swing.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class StreamDemo4 {
    public static void main(String[] args) {
        /**
         * 终结方法:
         * void forEach(Consumer action) 遍历
         * long count() 统计
         * toArray() 收集流中的数据，放到数组中
         * collect(collector collector)  收集流中的数据,放到集合中(tolist,toset,tomap)
         */
        ArrayList<String> list = new ArrayList<String>();
        Collections.addAll(list,"张三丰","张望角","张丽娜","赵四");
        list.stream().forEach(System.out::println);
        System.out.println("================================");
        //统计
        System.out.println(list.stream().count());
        System.out.println("================================");
        //收集流中的数据，放到数组中
        String[] s1 = list.stream().filter(s -> s.startsWith("赵")).toArray(value -> new String[value]);
        System.out.println(Arrays.toString(s1));
        //搜集集合中名字长度为2的并放入集合中
        System.out.println("================================");
        List<String> strings = list.stream().filter(s -> s.length()==2).toList();
        System.out.println(strings);
    }
}
